@extends('admin::layouts.master')

@section('content')
    <div class="col-lg-12">
        <div class="card card-table">
            <div class="card-header">
                友链管理
                <div class="mt-2">
                    <button type="button" class="btn btn-primary">友链列表</button>
                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#form-bp1">添加友链</button>
                    {{--调用引入组件的模板方法来引入某个组件模板--}}
                    {{--@component第二个参数数组中的键名,会自动的变成变量名,传递到被调用的组件模板中去--}}
                    @component('components.modal',['title' => '添加友链','url' => '/admin/link','id'=>'form-bp1'])
                        <div class="form-group">
                            <label>网站名称</label>
                            <input type="text" placeholder="请输入网站名称..." name="name" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>网址</label>
                            <input type="text" placeholder="请输入网址，比如：http://www.cdblog.xin" name="url" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>是否展示</label>
                            <div class="col-12 col-sm-8 col-lg-6 form-check mt-2">
                                <label class="custom-control custom-radio custom-control-inline">
                                    <input type="radio" name="show" checked="" class="custom-control-input" value="1"><span class="custom-control-label">是</span>
                                </label>
                                <label class="custom-control custom-radio custom-control-inline">
                                    <input type="radio" name="show" class="custom-control-input" value="0"><span class="custom-control-label">否</span>
                                </label>
                            </div>
                        </div>
                    @endcomponent
                    {{--调用引入组件的模板方法来引入某个组件模板--}}
                </div>
            </div>
            <div class="card-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>网站名称</th>
                        <th>网址</th>
                        <th>是否展示</th>
                        <th>创建时间</th>
                        <th class="actions">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $v)
                        <tr>
                            <td>{{$v['id']}}</td>
                            <td>{{$v['name']}}</td>
                            <td>{{$v['url']}}</td>
                            <td>{{$v['show']==1 ? '是' : '否'}}</td>
                            <td>{{$v['created_at']}}</td>
                            <td class="actions">
                                <div class="btn-group btn-space">
                                    <button type="button" class="btn btn-rounded btn-primary" data-toggle="modal" data-target="#form-bp2{{$v['id']}}">编辑</button>
                                    @component('components.modal',['title' => '修改友链','url' => '/admin/link/'.$v['id'],'id'=>'form-bp2'.$v['id'],'method'=>'PUT'])
                                        <div class="form-group">
                                            <label>网站名称</label>
                                            <input type="text" value="{{$v['name']}}" name="name" class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>网址</label>
                                            <input type="text" value="{{$v['url']}}" name="url" class="form-control">
                                        </div>
                                        <div class="form-group">
                                            <label>是否展示</label>
                                            <div class="col-12 col-sm-8 col-lg-6 form-check mt-2">
                                                <label class="custom-control custom-radio custom-control-inline">
                                                    <input type="radio" name="show" @if($v['show']==1) checked @endif class="custom-control-input" value="1"><span class="custom-control-label">是</span>
                                                </label>
                                                <label class="custom-control custom-radio custom-control-inline">
                                                    <input type="radio" name="show" @if($v['show']==0) checked @endif class="custom-control-input" value="0"><span class="custom-control-label">否</span>
                                                </label>
                                            </div>
                                        </div>
                                    @endcomponent
                                    <form action="/admin/link/{{$v['id']}}" onclick="return confirm('确定删除友链?')" method="post">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger">删除</button>
                                    </form>
                                    <a href="javascript:hald();" type="button" class="btn btn-rounded btn-success" >其他</a>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        {{--{{ $admins->links() }}--}}
    </div>
@stop

